'''
Created on Dec 6, 2009

@author: tliu
'''

import cgi
from util import AuthorizedPage
from error.TagError import TagError as TagError

class NewTagPage(AuthorizedPage):
    
    def postIfAuthorized(self):
        whitelist = ['/network', '/add_tags']
        redirect = self.request.get("redirect")
        if redirect not in whitelist:
            self.redirect('/error')
            return
        tag_name = cgi.escape(self.request.get("tag_name"))
        try:
            self.authorizedUser.addTag(tag_name)
        except TagError:
            self.redirect('/error')
            return
        self.redirect(redirect)
        if redirect == '/add_tags':
            redirect = '/add_tags?user=' + self.request.get("user")
        return
